class Student {
    public String nname;
    public int age;

}

class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println(this.name + this.age);
    }

    public void eat() {
        System.out.println(this.name + "正在吃饭");
    }

    public Animal() {
        super();
    }


}
class Cat extends Animal {
    public Cat(String name, int age) {
        super(name, age);
    }
    @Override//注解的
    public void eat() {
        System.out.println(this.name + "正再吃猫粮");//被重写的访问修饰限定符（子类）要大于等于父类的
    }
    public void miaomiao() {
        System.out.println(this.name + "喵喵叫");
    }

    @Override
    public String toString() {
        return "动物{" +
                "名字='" + name + '\'' +
                ", 年龄=" + age +
                '}';
    }

}
class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }
    @Override//注解的
          public void eat() {
        System.out.println(this.name + "正再吃狗粮");//被重写的访问修饰限定符（子类）要大于等于父类的
    }
    public void bark() {
        System.out.println(this.name + "旺旺叫");
    }

    @Override
    public String toString() {
        return "动物{" +
                "名字='" + name + '\'' +
                ", 年龄=" + age +
                '}';
    }

}


public class Main {

    public static void main1(String[] args) {
        Animal animal = new Dog("圆圆", 1);//先上转型

        //animal.eat();
       /* System.out.println(dog);
        dog.eat();//动态绑定*/
      /*  Cat cat= (Cat)animal;
        cat.miaomaio();*/
        if(animal instanceof Cat) {
            Cat cat = (Cat) animal;
            cat.miaomiao();
        }else{
            System.out.println("我理解了");

        }
    }
    public static void eatFun(Animal animal){
        animal.eat();

    }

    public static void main(String[] args) {
        Dog dog = new Dog("圆圆",2);
        eatFun(dog);
        Cat cat= new Cat("皮皮",3);//多态
        eatFun(cat);
    }
}
